<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateHelpRequestsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('help_requests', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id');
            $table->string('title', 200);
            $table->text('description');
            $table->boolean('is_urgent')->default(false);
            $table->boolean('is_anonymous')->default(false);
            $table->enum('status', ['open', 'resolved', 'closed'])->default('open');
            $table->text('ai_suggestion')->nullable()->comment('AI自动生成的建议');
            $table->unsignedBigInteger('best_answer_id')->nullable()->comment('最佳答案ID');
            $table->boolean('is_hidden')->default(false)->comment('是否被隐藏');
            $table->timestamps();
            
            // 外键约束
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            
            // 索引
            $table->index(['status']);
            $table->index(['created_at']);
            $table->index(['is_urgent']);
            $table->index(['is_hidden']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('help_requests');
    }
}